package as3.component.skin
{
	import com.seaengine.GameConfig;
	import com.seaengine.resourcemanager.ResSystem;
	import com.seaengine.resourcemanager.loadtool.ILoader;
	import com.seaengine.resourcemanager.loadtool.LoadUtils;
	import com.seaengine.util.BitmapScale9Grid;
	
	import flash.display.Bitmap;
	import flash.utils.setTimeout;

	/**
	 * 有关皮肤库信息
	 * 二〇一一年四月八日 20:13:27
	 */	
	public class SkinInfo
	{
	
		//--------------------------------------------------------------------------
		//
		//  variable
		//
		//--------------------------------------------------------------------------
		/**需要加载的皮肤库列表*/
		private var skinList:Array;
		
		/**九切片*/
		private var bitmapScale9Grid:BitmapScale9Grid;
		
		public function SkinInfo()
		{
			ResSystem.getInstance().getRes(GameConfig.m_ResConfig + "ui/skinList.xml", init);
			//ResSystem.getInstance().getRes("assets/ui/skinList.xml", init);
		}
	
		
		//--------------------------------------------------------------------------
		//
		//  private
		//
		//--------------------------------------------------------------------------
		private function init(fileName:String, data:Object):void
		{
			skinList = new Array();
			var xml:XMLList = (data as XML).item;
			var len:int = xml.length();
			for (var i:int = 0; i < len; i++)
			{
				//trace("id:"+xml[i].id + " xml:"+ xml[i].xml)
				skinList.push({name:xml[i].name,url:xml[i].url,scale9Grid:xml[i].scale9Grid});
			}
			setTimeout(function():void{ResSystem.getInstance().unloadRes(GameConfig.m_ResConfig + "ui/skinList.xml");},1000);
			
//			//功能地图标题图片
//			skinList.push({name:"FunMapTitle",url:"assets/ui/FunMapTitle.png"});
//			
//			//势力商店货币图标  temp
//			skinList.push({name:"DaBiaoJu",url:"assets/icon/dabiaoju.png"});
//			
//			//商店
//			skinList.push({name:"Glod",url:"assets/ui/glod.png"});
//			
//			skinList.push({name:"Affiliation",url:"assets/ui/Affiliation.png"});//门派贡献
//			
//			//雷达地图
//			skinList.push({name:"self",url:"assets/ui/self.png"});//自己
//			
//			skinList.push({name:"NPC",url:"assets/ui/NPC.png"});//npc
//			
//			skinList.push({name:"flagDarts",url:"assets/ui/flagDarts.png"});//镖旗
//			
//			skinList.push({name:"chest",url:"assets/ui/chest.png"});//宝箱
//			
//			//武功书店
//			skinList.push({name:"wgBookStore",url:"assets/ui/wgBookStore.png"});//书店渲染器
//			
//			skinList.push({name:"ybgz",url:"assets/ui/ybgz.png"});//元宝规则
//			
//			skinList.push({name:"silver",url:"assets/ui/silver.png"});//银两
//			
//			skinList.push({name:"mjjdt_0",url:"assets/ui/mjjdt_0.png"});//秘籍进度条
//			
//			skinList.push({name:"mjjdt_1",url:"assets/ui/mjjdt_1.png"});//秘籍进度条
//			
//			skinList.push({name:"mjjdt_2",url:"assets/ui/mjjdt_2.png"});//秘籍进度条
//			
//			skinList.push({name:"NAME_BACK",url:"assets/mijing/img/nameBack.png"});//秘籍进度条
//			
//			//恢复
//			skinList.push({name:"recover",url:"assets/ui/recover.png"});
//			
//			//行走
//			skinList.push({name:"peace",url:"assets/ui/peace.png"});
//			
//			//战斗
//			skinList.push({name:"battle",url:"assets/ui/battle.png"});
//			
//			//血瓶
//			skinList.push({name:"hpBottle",url:"assets/ui/hpBottle.png"});
//			
//			//魔瓶
//			skinList.push({name:"mpBottle",url:"assets/ui/mpBottle.png"});
//			
//			//分隔线
//			skinList.push({name:"mjResult",url:"assets/ui/mjResult.png"});
//			
//			//铜钱
//			skinList.push({name:"TQ",url:"assets/ui/TQ.png"});
			
			load();
		}
		
		private function load():void
		{
			var len:uint = skinList.length;
			var loadUtils:LoadUtils = new LoadUtils();
			for(var a:uint = 0; a < len; a++)
			{
				var url:String = skinList[a].url;
				var obj:Object = skinList[a].scale9Grid;
				var left:uint = skinList[a].scaleGridLeft;
				var right:uint = skinList[a].scaleGridRight;
				var top:uint = skinList[a].scaleGridTop;
				var bottom:uint = skinList[a].scaleGridBottom;
				loadUtils.addDisplayURL(url,loaderComplete,a,obj,left,right,top,bottom);
			}
			loadUtils.load();
		}
		//--------------------------------------------------------------------------
		//
		//  event
		//
		//--------------------------------------------------------------------------
		/**
		 * 加载完成
		 */		
		private function loaderComplete(iLoader:ILoader):void
		{
			var index:uint = iLoader.paramList[0];
			var obj:Object = iLoader.paramList[1];
//			var left:uint = iLoader.paramList[2];
//			var right:uint = iLoader.paramList[3];
//			var top:uint = iLoader.paramList[4];
//			var bottom:uint = iLoader.paramList[5];
			var name:String = skinList[index].name;
			var bitmap:Bitmap = Bitmap(iLoader.data.content);
			if(obj == true)
			{
				//bitmapScale9Grid = new BitmapScale9Grid(bitmap,top,bottom,left,right);
				bitmapScale9Grid = new BitmapScale9Grid(bitmap,5,bitmap.height-5,5,bitmap.width-5);
				Skin.setSkin(name,bitmapScale9Grid);
			}
			else
			{
				Skin.setSkin(name,bitmap);
			}
		}
	}
}